{extend name="sitehome@style/base"/}
{block name="resources"}
<style type="text/css">
	.keywords {height: 30px;display: inline-block;color: #000;font-size: 14px;line-height: 30px;cursor:pointer}
</style>
{/block}
{block name="main"}
 <div class="layui-form">
	<div class="layui-form-item">
		 <label class="layui-form-label sm"><span class="required">*</span>是否启用</label>
		 <div class="layui-input-inline">
			  <input type="checkbox" name="status" value="1" lay-skin="switch" {if $message_type_info['email_is_open'] eq 1}checked{/if}>
		 </div>
	 </div>
	 <div class="layui-form-item">
		 <label class="layui-form-label sm"><span class="required">*</span>邮件标题</label>
		 <div class="layui-input-inline">
			 <textarea placeholder="请输入内容" lay-verify="required" class="layui-textarea nc-len-long" name="title">{$email_message_info['title']}</textarea>
		 </div>
	 </div>
	 <div class="layui-form-item" enctype="multipart/form-data">
		 <label class="layui-form-label sm">邮件内容</label>
		 <div class="layui-input-inline">
			 {foreach name="$message_type_info['var_json']" item="item" key="k" }
			 <label href="javascript:;" class="keywords nc-input-text" onclick="button_key('{{$item}}')">【{$item}】</label>
			 {/foreach}
		 </div>
	 </div>
	 <div class="layui-form-item">
		 <label class="layui-form-label sm"></label>
	    <div class="layui-input-inline"><textarea id="email_content" class="nc-len-long">{$email_message_info['content']}</textarea></div>
	 </div>
     <div class="nc-form-row sm">
         <button class="layui-btn" lay-submit lay-filter="email">保存</button>
		 <button class="layui-btn layui-btn-primary" onclick="javascript:history.go(-1);">返回</button>
     </div>
	 <input type="hidden" name="template_id" value="{$email_message_info['template_id']}">
 </div>
{/block}
{block name="script"}
<script>
var editor = new Editor("email_content",{});
$(function(){
	if($("#email_content").val()){
		editor.setContent($("#email_content").val());
	}
});

layui.use('form', function() {
	var form = layui.form;
	var repeat_flag = false;//防重复标识
    form.on('submit(email)', function(data){
		if(repeat_flag) return;
		repeat_flag = true;
		var field = data.field;
        field.content = editor.getContent();
        field.keyword = "{$keyword}";
		$.ajax({
			type : "get",
			url : '{:addon_url("Email://sitehome/config/edit")}',
			data: field,
			dataType : "JSON",
			success : function(res) {
				repeat_flag = false;
				layer.msg(res.message);
				window.location.href= '{:addon_url("Message://sitehome/Index/index")}';
			}
		});
        return false;
    });
});

function button_key(v){
	editor.setContent(v,true);
}
</script>
{/block}